package com.hongkzh.www.friend.service;

import com.google.common.collect.Lists;
import com.hongkzh.www.adv.service.BaseService;
import com.hongkzh.www.conmon.*;
import com.hongkzh.www.user.service.UserService;
import com.jfinal.aop.Before;
import com.jfinal.aop.Enhancer;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.activerecord.tx.Tx;
import org.apache.commons.lang3.StringEscapeUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.*;

public class FriendService extends BaseService {


    public Map<String, List<Record>> friendList(String id) {
        SqlPara sqlPara = Db.getSqlPara("friend.friendList", id);
        List<Record> friends = Db.find(sqlPara);
        Map<String, List<Record>> map = new TreeMap(new Comparator<String>() {
            @Override
            public int compare(String obj1, String obj2) {
                // 降序排序
                return obj1.compareTo(obj2);
            }
        });
        String letter = null;
        List<Record> a = null;
        for (Record r : friends
                ) {
            a = null;
            doFilePath(r);
            letter = CnToSpell.getPinYinHeadChar(r.get("name"));
            r.set("letter", letter);
            if (null == map.get(letter)) {
                a = Lists.newArrayList();
                a.add(r);
                map.put(letter, a);
            } else {
                a = map.get(letter);
                a.add(r);
                map.put(letter, a);
            }
        }

        return map;
    }

    public Map<String, List<Record>> circleList(String id) {
        SqlPara sqlPara = Db.getSqlPara("friend.circleList", id);
        List<Record> friends = Db.find(sqlPara);
        Map<String, List<Record>> map = new TreeMap(new Comparator<String>() {
            @Override
            public int compare(String obj1, String obj2) {
                // 降序排序
                return obj1.compareTo(obj2);
            }
        });
        String letter = null;
        List<Record> a = null;
        for (Record r : friends
                ) {
            a = null;
            doFilePath(r);
            letter = CnToSpell.getPinYinHeadChar(r.get("circleName"));
            r.set("letter", letter);
            if (null == map.get(letter)) {
                a = Lists.newArrayList();
                a.add(r);
                map.put(letter, a);
            } else {
                a = map.get(letter);
                a.add(r);
                map.put(letter, a);
            }


        }

        return map;
    }

    public void addFriend(String uid, String friendId) {
        SqlPara sql = Db.getSqlPara("user.getfriend", friendId, uid);
        List<Record> friends = Db.find(sql);
        //不是好友
        if (friends == null || friends.size() == 0) {
            String id = IdGen.uuid();
            sql = Db.getSqlPara("user.friendAdd", id, friendId, uid);
            Db.update(sql);
        }
    }

    public void removeFriend(String uid, String friendId) {
        Db.delete(Db.getSql("friend.removeFriend"), friendId, uid, uid, friendId);
    }

    public void createGroup(String uid, String categoryId, String circleName, String coverImgSrc, String introduction, String isValidate, String coverImgWidth, String coverImgHeight) throws Exception {
        String groupId = IdGen.uuid();
        SqlPara sql = Db.getSqlPara("friend.createGroup", groupId, categoryId, uid, circleName, coverImgSrc, introduction, isValidate, coverImgWidth, coverImgHeight);
        Db.update(sql);
        RongCloudTool.createGroup(groupId, uid, circleName);
        String id = IdGen.uuid();
        sql = Db.getSqlPara("friend.joinGroup", id, uid, groupId);
        Db.update(sql);

    }

    public String joinGroup(String uid, String circleId) throws Exception {
        String returnStr = "已经申请或者加入了";
        SqlPara sql = Db.getSqlPara("friend.selectUserGroup", uid, circleId);
        Record record = Db.findFirst(sql);
        String id = record.get("id");
        String isValidate = record.get("isValidate");
        if (StrKit.isBlank(id)) {

            if (isValidate.equals("0")) {
                id = IdGen.uuid();
                sql = Db.getSqlPara("friend.joinGroup", id, uid, circleId);
                Db.update(sql);
                RongCloudTool.joinGroup(uid, circleId);
                returnStr = "申请加入成功";
            }
            else {
                Record p = Db.findFirst(Db.getSqlPara("friend.getGroupInfoBYId", circleId));
                Record u = Db.findFirst(Db.getSqlPara("user.getUserHeadImgInfo", uid));
                p.set("headImg", u.get("headImg"));
                p.set("uname", u.get("name"));
                p.set("uid", uid);
                p.set("content", "申请加入圈子" + p.get("cname"));
                p.set("createDate", DateUtil.FormatDateMMddHH(new Date()));
                p.set("type", "1");
                doImgPath(p);
                String data = JsonKit.toJson(p);
                Record r = new Record();
                r.set("type", "0");
                r.set("data", data);
                PushMessage.sendPush(p.get("cuid"), JsonKit.toJson(r), "申请加入圈子");
                returnStr = "申请加入!等待圈主审核";
            }
        }
        return returnStr;
    }

    public void quitGroup(String uid, String circleId) throws Exception {
        SqlPara sql = Db.getSqlPara("friend.quitGroup", uid, circleId);
        Db.update(sql);
        RongCloudTool.quitGroup(uid, circleId);
    }

    public String dismissGroup(String uid, String circleId) throws Exception {
        String result = "不是圈主不能解除圈子";
        SqlPara sql = Db.getSqlPara("friend.selectGroup", uid, circleId);
        Record record = Db.findFirst(sql);
        if (StrKit.notBlank(record.getStr("id"))) {
            sql = Db.getSqlPara("friend.dismissGroup", uid, circleId);
            Db.update(sql);
            sql = Db.getSqlPara("friend.dismissUserGroup", circleId);
            Db.update(sql);
            RongCloudTool.dismissGroup(uid, circleId);
            result = "";
        }
        return result;
    }

    public Record getGroupInfo(String uid, String circleId) {
        SqlPara sql = Db.getSqlPara("friend.getGroupInfo", uid, circleId);
        Record record = Db.findFirst(sql);
        record.set("state", StrKit.isBlank(record.getStr("state")) ? "1" : "2");
        doImgPath(record);
        sql = Db.getSqlPara("friend.getGroupProductInfo", circleId);
        List<Record> products = Db.find(sql);
        for (Record r : products
                ) {
            doImgPath(r);
        }
        sql = Db.getSqlPara("friend.getBoothMoney");
        record.set("boothMoney", Db.findFirst(sql).get("money"));
        record.set("products", products);

        sql = Db.getSqlPara("friend.getGroupMemberInfo", circleId);
        List<Record> members = Db.paginate(1, 5, sql).getList();
        for (Record r : members
                ) {
            doImgPath(r);
        }
        record.set("isMain", "0");
        if (uid.equals(record.get("uid"))) {
            record.set("isMain", "1");
        }
        record.set("members", members);
        sql = Db.getSqlPara("friend.getGroupPosts", circleId);
        List<Record> posts = Db.find(sql);

        record.set("posts", posts);
        return record;
    }
    public Page<Record> getMyDynamic(int pageNumber, String uid) {
        List<Record> records = Lists.newArrayList();
        Page<Record> p = new Page<Record>(records, pageNumber, StaticPublic.PAGESIZE, 0, 0);
        SqlPara sqlPara = Db.getSqlPara("friend.myMediaList", uid);

        List<Record> list = Db.find(sqlPara);
        for (Record r : list
        ) {
            r.set("publishhDate", DateUtil.CalculateTime(r.getStr("createDate")));
            doFilePath(r);
            records.add(r);
        }

        int totalRow = list.size();
        int totalPage = (int) (totalRow / StaticPublic.PAGESIZE);
        if (null != list && list.size() > 0) {
            list.subList(0, StaticPublic.PAGESIZE * (pageNumber - 1)).clear();
        }
        if (null != records && records.size() > 0) {
            p = new Page<Record>(records, pageNumber, StaticPublic.PAGESIZE, totalPage, totalRow);
        }
        return p;

    }
    public Page<Record> getFriendDynamic(int pageNumber, String uid) {
        List<Record> records = Lists.newArrayList();
        Page<Record> p = new Page<Record>(records, pageNumber, StaticPublic.PAGESIZE, 0, 0);
        SqlPara sqlPara = Db.getSqlPara("friend.friendMediaList", uid);

        List<Record> list = Db.find(sqlPara);
        for (Record r : list
                ) {
            r.set("publishhDate", DateUtil.CalculateTime(r.getStr("createDate")));
            doFilePath(r);
            records.add(r);
        }

        int totalRow = list.size();
        int totalPage = (int) (totalRow / StaticPublic.PAGESIZE);
        if (null != list && list.size() > 0) {
            list.subList(0, StaticPublic.PAGESIZE * (pageNumber - 1)).clear();
        }
        if (null != records && records.size() > 0) {
            p = new Page<Record>(records, pageNumber, StaticPublic.PAGESIZE, totalPage, totalRow);
        }
        return p;

    }

    public Page<Record> getFriendFollowDynamic(int pageNumber, String uid) {
        {
            List<Record> records = Lists.newArrayList();
            Page<Record> p = new Page<Record>(records, pageNumber, StaticPublic.PAGESIZE, 0, 0);
            SqlPara sqlPara = Db.getSqlPara("friend.getFriendFollowDynamic", uid);

            List<Record> list = Db.find(sqlPara);
            for (Record r : list
                    ) {
                r.set("publishhDate", DateUtil.CalculateTime(r.getStr("createDate")));
                doFilePath(r);
                records.add(r);
            }

            int totalRow = list.size();
            int totalPage = (int) (totalRow / StaticPublic.PAGESIZE);
            if (null != list && list.size() > 0) {
                list.subList(0, StaticPublic.PAGESIZE * (pageNumber - 1)).clear();
            }
            if (null != records && records.size() > 0) {
                p = new Page<Record>(records, pageNumber, StaticPublic.PAGESIZE, totalPage, totalRow);
            }
            return p;

        }
    }

    public List<Record> circleCategory() {
        SqlPara sql = Db.getSqlPara("friend.circleCategory");
        List<Record> lists = Db.find(sql);


        return lists;
    }

    public List<Record> circleCategoryList(String categoryId, String uid) {
        SqlPara sql = Db.getSqlPara("friend.circleCategoryList", categoryId, uid);
        List<Record> lists = Db.find(sql);
        for (Record r : lists
                ) {
            if (StrKit.isBlank(r.get("ucId"))) {
                r.set("ucId", "0");
            } else {
                r.set("ucId", "1");
            }
            doFilePath(r);
        }
        return lists;
    }

    public void confirmJoinGroup(String uid, String circleId) throws Exception {
        {
            SqlPara sql = Db.getSqlPara("friend.selectUserGroup", uid, circleId);
            Record record = Db.findFirst(sql);
            String id = record.get("id");

             if (StrKit.isBlank(id)) {
                id = IdGen.uuid();
                sql = Db.getSqlPara("friend.joinGroup", id, uid, circleId);
                Db.update(sql);
                RongCloudTool.joinGroup(uid, circleId);
            }

        }
    }

    public void kickOutGroup(String uid, String circleId, String loginUid) throws Exception {
        SqlPara sql = Db.getSqlPara("friend.kickOutGroup", uid, circleId, loginUid);
        int i = Db.update(sql);
        if (i > 0) {
            RongCloudTool.quitGroup(uid, circleId);
        }
    }

    public List<Record> getGroupMemberInfo(String uid, String circleId) {
        SqlPara sql = Db.getSqlPara("friend.getGroupMemberInfo", circleId);
        List<Record> list = Db.find(sql);
        int i = 0;
        for (Record r : list
                ) {
            r.set("state", "0");
            if (i == 0) {
                r.set("state", "1");
            }
            i++;
            doImgPath(r);
        }

        return list;
    }

    @Before(Tx.class)
    public void updateGroupRemind(String uid, String circleId, String remind) {
        Db.update(Db.getSqlPara("friend.updateGroupRemind", uid, circleId, remind));
    }

    @Before(Tx.class)
    public void setNotice(String uid, String state, String postId) {
        Db.update(Db.getSqlPara("friend.setNotice", postId, state));
    }

    @Before(Tx.class)
    public void setSelected(String uid, String state, String postId) {
        Db.update(Db.getSqlPara("friend.setSelected", postId, state));

        Record p=Db.findFirst(Db.getSqlPara("friend.getPostsById",postId));
        Record u=Db.findFirst(Db.getSqlPara("user.getUserHeadImgInfo",uid));
       /* p.set("headImg",u.get("headImg"));
        p.set("uname",u.get("name"));*/
        p.set("content","你的帖子被圈主设为精华");
        p.set("type","0");
        p.set("createDate",DateUtil.FormatDateMMddHH(new Date()));
        doImgPath(p);
        String data=JsonKit.toJson(p);
        Record r=new Record();
        r.set("type","0");
        r.set("data",data);

        PushMessage.sendPush(uid,JsonKit.toJson(r),"你的帖子被圈主设为精华");
    }

    @Before(Tx.class)
    public void setTop(String uid, String state, String postId) {
        Db.update(Db.getSqlPara("friend.setTop", postId, state));
    }

    public Record getPost(String uid, String postId) {
        Record record = Db.findFirst(Db.getSqlPara("friend.getPost",postId,uid));
        record.set("createDate",DateUtil.FormatDateMMdd(record.get("createDate")));
        if(null!=record){
            record.set("isPostUser","0");
            if(record.getStr("uid").equals(uid)){
                record.set("isPostUser","1");
            }
            record.set("isCircleUser","0");
            if(record.getStr("usecircle").equals(uid)){
                record.set("isCircleUser","1");
            }
            record.set("isPraise","0");
            if(StrKit.notBlank(record.getStr("ppid"))){
                record.set("isPraise","1");
            }
            doImgList(record);
        }
        doImgPath(record);
        doNumberPath(record);
        return record;
    }
    @Before(Tx.class)
    public void deletePost(String uid, String postId, String delType) {
        Db.update(Db.getSqlPara("friend.updateDelPost",postId,uid,delType));
    }
    @Before(Tx.class)
    public Record praisePost(String uid, String postId, String state) {
        if(state.equals("1")) {
            Db.update(Db.getSqlPara("friend.addPostPraiseCount", postId));
            String id=IdGen.uuid();
            Db.update(Db.getSqlPara("friend.addpraisePost",id, postId, uid));

        }
        else{
            Db.update(Db.getSqlPara("friend.reducePostPraiseCount", postId));
            Db.update(Db.getSqlPara("friend.reducepraisePost", postId, uid));
        }
        Record r=Db.findFirst(Db.getSqlPara("friend.postsPraise",postId));
        doNumberPath(r);
        return r ;
    }

    public Page<Record> getCommentsByPostId(String id, int pageNumber) {
        SqlPara sqlPara = Db.getSqlPara("friend.getCommentsByPostId", id);
        Page<Record> records = Db.paginate(pageNumber, 6, sqlPara);

        for (Record r : records.getList()) {
            r.set("createDate",DateUtil.CalculateTime(r.getStr("createDate")));
            doImgPath(r);
        }
        return records;

    }

    @Before(Tx.class)
    public void savePost(String loginUid, String circleId, String title, String content) {
       String id=IdGen.uuid();
        content=StringEscapeUtils.unescapeHtml4(content);
        SqlPara sqlPara = Db.getSqlPara("friend.savePost", id,loginUid,circleId,title,content);
         Db.update(sqlPara);

    }
    @Before(Tx.class)
    public void updateGroupIntroduction(String uid, String circleId, String introduction) {
        SqlPara sqlPara = Db.getSqlPara("friend.updateGroupIntroduction", circleId,introduction,uid);
        Db.update(sqlPara);
    }
    @Before(Tx.class)
    public void updateGroupCategory(String uid, String circleId, String categoryId) {
        SqlPara sqlPara = Db.getSqlPara("friend.updateGroupCategory", circleId,categoryId,uid);
        Db.update(sqlPara);
    }
    @Before(Tx.class)
    public void updateGroupName(String uid, String circleId, String name) {
        SqlPara sqlPara = Db.getSqlPara("friend.updateGroupName", circleId,name,uid);
        Db.update(sqlPara);
    }
    @Before(Tx.class)
    public void updateGroupCoverImgSrc(String uid, String circleId, String coverImgSrc, String coverImgWidth, String coverImgHeight) {
        SqlPara sqlPara = Db.getSqlPara("friend.updateGroupCoverImgSrc", circleId,uid,coverImgSrc,coverImgWidth,coverImgHeight);
        Db.update(sqlPara);
    }
    @Before(Tx.class)
    public void updateGroupValidate(String uid, String circleId, String isValidate) {
        SqlPara sqlPara = Db.getSqlPara("friend.updateGroupValidate", circleId,isValidate,uid);
        Db.update(sqlPara);
    }
    @Before(Tx.class)
    public void updateGroupUpperLlimit(String uid, String circleId, String upperLlimit) {
        SqlPara sqlPara = Db.getSqlPara("friend.updateGroupUpperLlimit", circleId,upperLlimit,uid);
        Db.update(sqlPara);
    }

    public List<Record> getProductList(String uid) {
        SqlPara sql = Db.getSqlPara("friend.getProductList", uid);
        List<Record> products = Db.find(sql);
        for (Record r : products
                ) {
            doImgPath(r);
        }
        return products;
    }
    @Before(Tx.class)
    public void addCircleProduct(String uid, String productId, String circleId) {

        SqlPara sqlPara = Db.getSqlPara("friend.saveCircleProduct",IdGen.uuid(), circleId,productId,uid);
        Db.update(sqlPara);
    }
    @Before(Tx.class)
    public void deleteCircleProduct(String uid, String productId, String circleId) {
        SqlPara sqlPara = Db.getSqlPara("friend.deleteCircleProduct", circleId,productId,uid);
        Db.update(sqlPara);
    }
    @Before(Tx.class)
    public void buyBooth(String loginUid,String circleId) throws Exception {

        UserService userService=Enhancer.enhance(UserService.class);
        int boothMoney=Db.findFirst(Db.getSqlPara("friend.getBoothMoney")).getInt("money");
        userService.reduceIntegral(loginUid,boothMoney,"购买圈子展位");

            SqlPara sqlPara = Db.getSqlPara("friend.buyBooth", circleId, loginUid,1);
            Db.update(sqlPara);

    }

    public Page<Record> getInfoPostCommentList(String id, int pageNumber, String loginUid) {
        SqlPara sqlPara = Db.getSqlPara("friend.getInfoPostCommentList", id,loginUid);
        Page<Record> records = Db.paginate(pageNumber, 10, sqlPara);

        for (Record r : records.getList()) {
            doFilePath(r);
            doNumberPath(r);
            r.set("praiseState","0");
            if(StrKit.notBlank(r.getStr("praiseId"))){
                r.set("praiseState","1");
            }
            r.set("createDate",DateUtil.CalculateTime(r.getStr("createDate")));
        }
        return records;
    }

    public Page<Record> getInfoPostCommentReplyList(String commentId, int pageNumber) {
        SqlPara sqlPara = Db.getSqlPara("friend.getInfoPostCommentReplyList", commentId);
        Page<Record> records = Db.paginate(pageNumber, 10, sqlPara);

        for (Record r : records.getList()) {
            doFilePath(r);
            r.set("createDate",DateUtil.CalculateTime(r.getStr("createDate")));
        }
        return records;
    }
    @Before(Tx.class)
    public Record praisePostComment(String commentId, String loginUid, int state) {
        if(state==0){
            Db.update(Db.getSqlPara("friend.reducePraisecount",commentId));
            Db.update(Db.getSqlPara("friend.deletePraise",commentId,loginUid));
        }
        else{
            Db.update(Db.getSqlPara("friend.addPraisecount",commentId));
            Db.update(Db.getSqlPara("friend.savePraise",commentId,loginUid));
        }

        Record record=Db.findFirst(Db.getSqlPara("friend.getPraisecount",commentId));
        doNumberPath(record);
        return record;
    }
    @Before(Tx.class)
    public void postComment(String loginUid, String commentId, String ruserId, String content, String id) {
        if(StrKit.notBlank(commentId)){
            Db.update(Db.getSqlPara("friend.savePostCommentReply", IdGen.uuid(),commentId,loginUid,ruserId,content,id));
        }
        else{
            Db.update(Db.getSqlPara("friend.savePostComment", IdGen.uuid(),id,loginUid,content));
            Record p=Db.findFirst(Db.getSqlPara("friend.getPostsById",id));
            Record u=Db.findFirst(Db.getSqlPara("user.getUserHeadImgInfo",loginUid));
            p.set("headImg",u.get("headImg"));
            p.set("uname",u.get("name"));
            p.set("content","回复:"+content);
            p.set("type","0");
            p.set("createDate",DateUtil.FormatDateMMddHH(new Date()));
            doImgPath(p);
            String data=JsonKit.toJson(p);
            Record r=new Record();
           r.set("type","0");
           r.set("data",data);

            PushMessage.sendPush(loginUid,JsonKit.toJson(r),"评论了你的帖子");
        }
    }
    @Before(Tx.class)
    public  void forwardPost(String uid, String title, String model, String modelId, String coverImgSrc, String modelName, String circleId) {
        if(model.equals("4")) {
            Db.update(Db.getSqlPara("friend.saveforwardPost", IdGen.uuid(), modelId, uid));
        }
        Db.update(Db.getSqlPara("friend.savecircleforwardPost", IdGen.uuid(),title, modelName,model,modelId,coverImgSrc,uid,circleId));

    }

    public Page<Record> getCirclePost(String loginUid, String circleId, int pageNumber, String state) {
        Kv cond=Kv.by("circleId",circleId);
        cond.set("uid","and pp.user_id='"+loginUid+"'");
        if(state.equals("1")){
            cond.set("order2"," order by c.create_date desc");
        }
        else if(state.equals("2")){
            cond.set("order2"," order by c.create_date desc");
        }
        else if(state.equals("3")){
            cond.set("order2"," order by c.isSelected desc ");
        }
        SqlPara sqlPara = Db.getSqlPara("friend.getCirclePost",  cond);

        Page<Record> records = Db.paginate(pageNumber, 10, sqlPara);

        for (Record r : records.getList()) {
            doImgPath(r);
            doNumberPath(r);
            r.set("createDate",DateUtil.CalculateTime(r.getStr("createDate")));
            doImgList(r);
            r.set("content","");
            r.set("isPraise","0");
            if(StrKit.notBlank(r.getStr("ppid"))){
                r.set("isPraise","1");
            }
        }
        return records;

    }


    private void doImgList(Record r){
        List<String> imgs=Lists.newArrayList();
        r.set("imgList",imgs);
        if(StrKit.notBlank(r.getStr("content"))) {
            Document containerDoc = Jsoup.parse(r.getStr("content"));
            Elements e = containerDoc.select("img");
            int i = 0;
            for (Element ee : e) {
                if (i > 3) {
                    break;
                }
                imgs.add(ee.attr("src"));
                i++;
            }
            r.set("imgList", imgs);
        }
    }


    public Record search(String id, String name) {
        Record r=new Record();
        SqlPara sqlPara = Db.getSqlPara("friend.searchfriendList", id,name);
        List<Record> friends = Db.find(sqlPara);
        friends=friends.size()>3?friends.subList(0,2):friends;
        for (Record r1 : friends
                ) {
            doImgPath(r1);
        }
        r.set("friends",friends);
          sqlPara = Db.getSqlPara("friend.searchcircleList", id,name);
        List<Record> circles = Db.find(sqlPara);
        for (Record r1 : circles
                ) {
            doImgPath(r1);
        }
        r.set("circles",circles);

        return  r;
    }

    public List<Record> searchfriendList(String id, String name) {

        SqlPara sqlPara = Db.getSqlPara("friend.searchfriendList", id,name);
        List<Record> friends = Db.find(sqlPara);
        for (Record r1 : friends
                ) {
            doImgPath(r1);
        }
        return friends ;
    }

    public List<Record> searchcirclenotinList(String id, String name) {
        SqlPara sqlPara = Db.getSqlPara("friend.searchcirclenotinList", id,name);
        List<Record> friends = Db.find(sqlPara);
        for (Record r1 : friends
                ) {
            doImgPath(r1);
        }
        return friends ;
    }

    public Record getUserInfoByUid(String loginUid, String uid) {
        Record r=Db.findFirst(Db.getSqlPara("user.getUserInfoByUid",uid));
        doImgPath(r);
        return r;
    }

    public List<Record> searchcircleList(String loginUid, String name) {
        List<Record> circles = Db.find(Db.getSqlPara("friend.searchcircleList", loginUid,name));
        for (Record r1 : circles
                ) {
            doImgPath(r1);
        }
        return circles;
    }

    public Record getInfoPostCommentById(String postId, String loginUid) {
        SqlPara sqlPara = Db.getSqlPara("friend.getInfoPostCommentById", postId,loginUid);
          Record  r = Db.findFirst(sqlPara);

            doFilePath(r);
            doNumberPath(r);
            r.set("praiseState","0");
            if(StrKit.notBlank(r.getStr("praiseId"))){
                r.set("praiseState","1");
            }
            r.set("createDate",DateUtil.CalculateTime(r.getStr("createDate")));
            return  r;
    }

    public void addBlack(String id, String friendId) throws Exception {
        Db.update(Db.getSqlPara("friend.addBlack",IdGen.uuid(), id,friendId));
        RongCloudTool.addBlacklist(id, Db.find(Db.getSqlPara("friend.blackList",id)));
    }

    public void removeBlack(String id, String friendId) throws Exception {
        Db.update(Db.getSqlPara("friend.removeBlack",id,friendId));
        RongCloudTool.addBlacklist(id, Db.find(Db.getSqlPara("friend.blackList",id)));

    }

    public Page<Record> blackList(String id, int pageNumber) {
        Page<Record> page=Db.paginate(pageNumber,StaticPublic.LARGEPAGESIZE,Db.getSqlPara("friend.blackLists",id));
        for (Record record:page.getList()
             ) {
            doImgPath(record);
        }
      return page;
    }
}
